<?php 
class RazasController extends AppController{
    
    public $layout = 'kennel';
    public $name = 'Razas';
    public $helpers=array('Html','Form');
    public $components=array('Session');
    public $uses = array('Raza', 'Grupo');
   
   
    function index(){
	    
	    $razas=$this->Raza->find('all');
	    
	    $this->set(compact('razas'));
	    
    }
    function insertar($id = null){
        if(!empty($this->data)){
            $this->Raza->create();
            
            if($this->Raza->save($this->data)){
                
                $this->Session->setFlash("Raza".$this->Raza->id." guardada");
                $this->redirect(array('action'=>'index'), null, true);
            }else{
                $this->Session->setFlash("No se pudo guardar");
                $this->redirect(array('action'=>'index'), null, true);
            }
        }
    }
    function editar($id=null){
        $this->Raza->id = $id;
                if (!$id) {
                    $this->Session->setFlash('No existe tal registro');
                    $this->redirect(array('action' => 'index'), null, true);
                }
                if (empty($this->data)) {
                    $this->data = $this->Raza->read(); 
                    
                } else {
                    if ($this->Raza->save($this->data)) {
                        $this->Session->setFlash('Los datos fueron modificados');
                        $this->redirect(array('action' => 'index'), null, true);
                    } else {
                        $this->Session->setFlash('no se pudo modificar!!');
                    }
                }
    }
     public function eliminar($id = null){
        if (!$id) {
            $this->Session->setFlash('id Invalida para borrar');
            $this->redirect(array('action' => 'index'));
        }
        if ($this->Raza->delete($id)) {
           $this->Session->setFlash('la raza ' . $id . ' fue borrada');
           $this->redirect(array('action' => 'index'));
        }

    }
    
}
?>